package hlhj.com.carviewpad.modules

import android.content.Context
import com.example.mymvp.mvp.BaseModule
import com.lzy.okgo.model.Response
import hlhj.com.carviewpad.Iviews.MainVIew
import hlhj.com.carviewpad.http.Apis
import hlhj.com.carviewpad.http.CustomAction
import hlhj.com.carviewpad.http.LoadingAction
import hlhj.com.carviewpad.javabean.FilesBean
import hlhj.com.carviewpad.javabean.GameBean
import hlhj.com.carviewpad.javabean.IdBean
import hlhj.com.carviewpad.javabean.MyBaseBean

/**
 * Created by Never Fear   on 2018\12\28 0028.
Never More....
 */
class MainModule :BaseModule {
    var lis:MainVIew?=null
    //获取广告文件
    fun getFiles(c:Context){
            Apis?.getFiles()
                    ?.let {
                        it.doOnSubscribe(LoadingAction(c))
                                .subscribe(object :CustomAction<Response<FilesBean>>(c){
                                    override fun httpSuccess(t: Response<FilesBean>) {
                                        lis?.setFilesBean(t.body())
                                    }
                                })
                    }
    }
    //获取设备信息
    fun getEquipmentInfo(device_sn:String,c:Context){
        Apis?.getIds(device_sn)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<IdBean>>(c){
                                override fun httpSuccess(t: Response<IdBean>) {
                                    lis?.setIds(t.body())
                                }
                            })
                }
    }
    //获取公告
    fun getNotce(c:Context){
        Apis?.getNotice(c)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<MyBaseBean>>(c){
                                override fun httpSuccess(t: Response<MyBaseBean>) {
                                    lis?.setNotce(t.body())
                                }
                            })
                }
    }
    //获取是否有更新
    fun getisUpdata(c:Context){
        Apis.getIsupdata(c)
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<MyBaseBean>>(c){
                                override fun httpSuccess(t: Response<MyBaseBean>) {
                                    lis?.setIsUpdata(t.body())
                                }
                            })
                }
    }
    //获取游戏信息
    fun getGame(c:Context){
        Apis.getGame()
                ?.let {
                    it.doOnSubscribe(LoadingAction(c))
                            .subscribe(object :CustomAction<Response<GameBean>>(c){
                                override fun httpSuccess(t: Response<GameBean>) {
                                    lis?.setGame(t.body())
                                }
                            })
                }
    }
}